// by Xeno
#include "x_setup.sqf"
private ["_poss", "_grps", "_units", "_endnum"];
if (!isServer) exitWith {};

_poss = _this select 0;

#ifdef __TT__
sm_points_west = 0;
sm_points_east = 0;
#endif

_pos_array = nil;

_grps = ["specops", 3, "basic", 0, _poss , 50, true] call XCreateInf;
_units = [];
{_units = [_units, units _x] call X_fnc_arrayPushStack} forEach _grps;

d_num_species = 0;
#ifdef __TT__
{_x addEventHandler ["killed", {_this call XfAddSMPoints}]} forEach _units;
#endif
{_x allowFleeing 0;_x addEventHandler ["killed", {d_num_species = d_num_species + 1}]} forEach _units;
sleep 2.123;
_endnum = (count _units) - 2;

while {d_num_species < _endnum} do {
	{
		if (alive _x) then {
			_dist = _x distance _poss;
			if (_dist > 200 && _dist < 400) then {
				(leader _x) doMove _poss;
			} else {
				if (_dist >= 400) then {_x setDamage 1};
			};
			sleep 0.01;
		};
	} forEach _units;
	sleep 4.631;
};

_units = nil;

#ifndef __TT__
d_side_mission_winner=2;
#else
if (sm_points_west > sm_points_east) then {
	d_side_mission_winner = 2;
} else {
	if (sm_points_east > sm_points_west) then {
		d_side_mission_winner = 1;
	} else {
		if (sm_points_east == sm_points_west) then {
			d_side_mission_winner = 123;
		};
	};
};
#endif
d_side_mission_resolved = true;